package com.zzyl.common.ai;


import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.core.auth.Auth;
import com.baidubce.qianfan.model.chat.ChatResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AIModelInvoker {
    @Autowired
    private AIModelProperties aiModelProperties;
    public String qianfanInvoker(String prompt){

        Qianfan qianfan = new Qianfan(Auth.TYPE_OAUTH,aiModelProperties.getAccessKey(), aiModelProperties.getSecretKey());
        // 指定模型
        ChatResponse resp = qianfan.chatCompletion()
                .model(aiModelProperties.getModel())   // 指定模型
                .addMessage("user", prompt)  //添加用户消息
                .temperature(0.8) // 温度系数，取值范围(0,1.0]，默认为0.8
                .maxOutputTokens(2048)
                .responseFormat("json_object")
                .execute();  // 执行请求

                return resp.getResult();
    }
}
